

package com.liulishuo.filedownloader.i;


import com.liulishuo.filedownloader.message.MessageSnapshot;
import com.liulishuo.filedownloader.i.FileDownloadIPCCallbackProxy;
import ohos.rpc.IRemoteBroker;
import ohos.rpc.IRemoteObject;
import ohos.rpc.RemoteException;
import ohos.rpc.RemoteObject;
import ohos.rpc.MessageParcel;
import ohos.rpc.MessageOption;

public abstract class FileDownloadIPCCallbackStub extends RemoteObject implements IFileDownloadIPCCallback {
    public final String TAG = FileDownloadIPCCallbackStub.class.getSimpleName();
    private static final String DESCRIPTOR = "com.liulishuo.filedownloader.i.IFileDownloadIPCCallback";

    private static final int COMMAND_CALLBACK = IRemoteObject.MIN_TRANSACTION_ID + 0;

    private static final int ERR_OK = 0;
    private static final int ERR_RUNTIME_EXCEPTION = -1;

    public FileDownloadIPCCallbackStub(
            /* [in] */ String descriptor) {
        super(descriptor);
    }

    @Override
    public IRemoteObject asObject() {
        return this;
    }

    public static IFileDownloadIPCCallback asInterface(IRemoteObject object) {
        if (object == null) {
            return null;
        }

        IFileDownloadIPCCallback result = null;
        IRemoteBroker broker = object.queryLocalInterface(DESCRIPTOR);
        if (broker != null) {
            if (broker instanceof IFileDownloadIPCCallback) {
                result = (IFileDownloadIPCCallback) broker;
            }
        } else {
            result = new FileDownloadIPCCallbackProxy(object);
        }

        return result;
    }

    @Override
    public boolean onRemoteRequest(
            /* [in] */ int code,
            /* [in] */ MessageParcel data,
            /* [out] */ MessageParcel reply,
            /* [in] */ MessageOption option) throws RemoteException {
        String token = data.readInterfaceToken();


        if (!DESCRIPTOR.equals(token)) {
            return false;
        }
        /*



         */
        switch (code) {
            case COMMAND_CALLBACK: {

                MessageSnapshot snapshot = MessageSnapshot.Producer.createFromParcel(data);

                //data.readSequenceable(snapshot);
                callback(snapshot);
                reply.writeNoException();
                return true;
            }
            default:
                return super.onRemoteRequest(code, data, reply, option);
        }
    }
};

